﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
using System.Windows.Media;
using ThreeByte.ActiveDeck.Content;

namespace ThreeByte.ActiveDeck.Converters
{
    public class OrientationToTransformConverter : IValueConverter
    {
        private static RotateTransform Portrait = null;
        private static RotateTransform LeftLandscape = new RotateTransform(90);
        private static RotateTransform RightLandscape = new RotateTransform(270);
        private static RotateTransform UpsideDown = new RotateTransform(180);

        public bool Reverse { get; set; }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            
            Orientation o = Orientation.Portrait;
            if(value is Orientation) {
                o = (Orientation)value;
            }

            switch(o){
                case Orientation.LandscapeLeft: return (Reverse ? RightLandscape : LeftLandscape);
                case Orientation.LandscapeRight: return (Reverse ? LeftLandscape : RightLandscape);
                case Orientation.UpsideDown: return UpsideDown;
                default:
                    return Portrait;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            throw new Exception("Cannot convert back from OrientationToTransformConverter");
        }
    }
   
}
